#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jul 11 22:37:53 2023

@author: liqingsimac
"""
import numpy as np
A=np.array([
[5,2,1,4,0,0,2,4,0,0,0],
[0,0,0,0,0,0,0,0,0,3,0],
[1,0,5,2,0,0,3,0,3,0,1],
[0,5,0,0,4,0,1,0,0,0,0],
[0,0,0,0,0,4,0,0,0,4,0],
[0,0,1,0,0,0,1,0,0,5,0],
[5,0,2,4,2,1,0,3,0,1,0],
[0,4,0,0,5,4,0,0,0,0,5],
[0,0,0,0,0,0,4,0,4,5,0],
[0,0,0,4,0,0,1,5,0,0,0],
[0,0,0,0,4,5,0,0,0,0,3],
[4,2,1,4,0,0,2,4,0,0,0],
[0,1,4,1,2,1,5,0,5,0,0],
[0,0,0,0,0,4,0,0,0,4,0],
[2,5,0,0,4,0,0,0,0,0,0],
[5,0,0,0,0,0,0,4,2,0,0],
[0,2,4,0,4,3,4,0,0,0,0],
[0,3,5,1,0,0,4,1,0,0,0]])

#np.set_printoptions(precision=2, suppress=True)   
# 设置显示三位小数点，并且不用科学计数法显示

M=np.mean(A,axis=0)
C=A-M
R=np.zeros([11,11])
for i in range(11):
    for j in range(11):
        num = np.sum(C[:,i]*C[:,j])
        denom = np.sqrt(np.sum(C[:,i]**2))*np.sqrt(np.sum(C[:,j]**2))
        R[i,j] = num/denom

R2=np.corrcoef(A)
S=(R+1)/2
#print(R)

'''
b_17_0_num = A[17,1]*S[1,0]+ A[17,2]*S[2,0] + \
    A[17,3]*S[3,0]+ A[17,6]*S[6,0]+ A[17,7]*S[7,0]
b_17_0_denom = S[1,0]+S[2,0]+S[3,0]+S[6,0]+S[7,0]
b_17_0 = b_17_0_num/b_17_0_denom
print('对高辛推荐菜品1的打分估计为：%.2f'%b_17_0)
'''

# 高辛已评菜品：1,2,3,6,7, 未评菜品：0,4,5,8,9,10

for k in (0,4,5,8,9,10):
    b_17_k_num = A[17,1]*S[1,k]+ A[17,2]*S[2,k] + \
        A[17,3]*S[3,k]+ A[17,6]*S[6,k]+ A[17,7]*S[7,k]
    b_17_k_denom = S[1,k]+S[2,k]+S[3,k]+S[6,k]+S[7,k]
    b_17_k = b_17_k_num/b_17_k_denom
    print('对高辛推荐菜品%d的打分估计为：%.2f.'%(k,b_17_k))

print('\n')

TupleA=(1,2,3,6,7)
TupleB=(0,4,5,8,9,10)

for k in TupleB:
    b_17_num=0
    b_17_denom=0
    for m in TupleA:
        b_17_num=b_17_num + A[17,m]*S[m,k]
        b_17_denom=b_17_denom + S[m,k]
    b_17 = b_17_num/b_17_denom
    print('对高辛推荐菜品%d的打分估计为：%.2f.'%(k,b_17))
   


    





